package com.fz.study.project.controller;


import com.fz.study.project.entity.Result;
import com.fz.study.project.entity.dto.LoginFormDTO;
import com.fz.study.project.entity.dto.UserDTO;
import com.fz.study.project.service.ITbUserService;
import com.fz.study.project.utils.UserHolder;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2024-02-25
 */
@Tag(name = "使用电话号码登录")
@RestController
@RequiredArgsConstructor
@RequestMapping("/user")
public class UserController {
    private final ITbUserService userService;

    @Operation(summary = "生成手机号验证码")
    @PostMapping("code")
    public Result sendCode(@RequestParam("phone") String phone){
        return Result.success(userService.sendCode(phone));
    }

    @Operation(summary = "校验登录")
    @PostMapping("login")
    public Result login(@RequestBody LoginFormDTO loginFormDTO){
        return userService.login(loginFormDTO);
    }
    @GetMapping("me")
    public Result me(){
        UserDTO user = UserHolder.getUser();
        return Result.success(user);
    }

}
